package com.leo.offer;

/**
 *
 * @author xuexiaolei
 * @version 2018年03月01日
 */
public class Node {
    int val;
    Node next;

    public Node() {
    }

    public Node(int val) {
        this.val = val;
    }

    public Node(int val, Node next) {
        this.val = val;
        this.next = next;
    }

    /**
     * 用数组构建一个链表
     * @param a
     * @return
     */
    public static Node createNode(int[] a){
        if (a==null || a.length==0){ return null; }
        Node head = new Node(a[0]);
        Node cur = head;
        for (int i = 1; i < a.length; i++) {
            Node n = new Node(a[i]);
            cur.next = n;
            cur = cur.next;
        }
        return head;
    }

    public static void printNode(Node node){
        while (node != null){
            System.out.print(node.val+" --> ");
            node = node.next;
        }
        System.out.println();
    }

    public static void main(String[] args) {
        Node node = createNode(new int[] {1, 2, 3, 4, 5, 6});
        printNode(node);
    }
}
